home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Misc / AnimTester / Source / AnimView.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  2.7 KB  |  102 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "AnimView.h"
  5. #import <appkit/NXImage.h>
  6. #import <appkit/Control.h>
  7. #import <appkit/Matrix.h>
  8. #import <dpsclient/psops.h>
  9.  
  10. @implementation AnimView
  11.  
  12. - initFrame:(const NXRect *)frm    // initialize instance
  13. {
  14.     [super initFrame:frm];
  15.     cycles = 0;
  16.     frameShown = 0;
  17.     position.y = 0.0;
  18.     position.x = 0.0;
  19.     return self;
  20. }
  21.  
  22. - loadPix                // gameBrain calls this from appDidInit
  23. {
  24.     [super loadPix];
  25.     runner = [NXImage findImageNamed:IMAGENAME];
  26.     return self;
  27. }
  28.  
  29. - autoUpdate:sender    // sent by timer
  30. {
  31.     int direction = GODIR;
  32.     int move = MOVEINC;
  33.     
  34.     [super autoUpdate:sender];
  35.     if (!(cycles % UPDATEFREQ)) {
  36.         frameShown++;
  37.         if (frameShown >= NUM_FRAMES) frameShown = 0;
  38.         if (GORIGHT) {
  39.             position.x = position.x + move;
  40.             if (position.x > NX_WIDTH(&bounds) + move) position.x = 0.0;
  41.         } else if (GOLEFT) {
  42.             position.x = position.x - move;
  43.             if (position.x < - (BLOCK_SIZE + move)) position.x = NX_WIDTH(&bounds);
  44.         } else if (GOUP) {
  45.             position.y = position.y + move;
  46.             if (position.y > NX_HEIGHT(&bounds) + move) position.y = 0.0;
  47.         } else if (GODOWN) {
  48.             position.y = position.y - move;
  49.             if (position.y < - (BLOCK_SIZE + move)) position.y = NX_HEIGHT(&bounds);
  50.         } else {
  51.         }
  52.         [self updateSelf:&bounds :1]; 
  53.     }
  54.     return self;
  55. }
  56.  
  57. - drawSelf:(NXRect *)rects :(int)rectCount  //used by internals for speed
  58. {
  59.     NXRect from = {{frameShown * BLOCK_SIZE, SERIES * BLOCK_SIZE},
  60.         {BLOCK_SIZE, BLOCK_SIZE}};
  61.     
  62.     [super drawSelf:rects :rectCount];
  63.     PSsetgray(0.333);
  64.     NXRectFill(rects);
  65.     [runner composite:NX_SOVER fromRect:&from toPoint:&position];
  66.     return self;
  67. }
  68.  
  69. - updateSelf:(NXRect *)rects :(int)rectCount  //used by internals for speed
  70. {
  71.     int move = MOVEINC;
  72.     NXRect from = {{frameShown * BLOCK_SIZE, SERIES * BLOCK_SIZE},
  73.         {BLOCK_SIZE, BLOCK_SIZE}};
  74.     NXRect old = {{position.x  - move, position.y - move},
  75.         {BLOCK_SIZE + move * 2, BLOCK_SIZE + move * 2}};
  76.     
  77.     [self lockFocus];
  78.     [super drawSelf:rects :rectCount]; // very inefficient (GameView will splat the
  79.     // whole background!)  Probably OK to comment it out.
  80.     PSsetgray(0.333);
  81.     NXRectFill(&old); // since there is only one object, the DirtPile is overkill and
  82.     // I just use regular NEXTSTEP buffers- they'll flush to the screen the erased
  83.     // area intersected with the newly composited area.  Quite simple, really.  The
  84.     // DirtPile will do this intelligently if you have more objects than one.
  85.     [runner composite:NX_SOVER fromRect:&from toPoint:&position];
  86.     [self unlockFocus];
  87.     [window flushWindow];
  88.     NXPing();  // Only one ping per frame or you'll crawl!
  89.     return self;
  90. }
  91.  
  92. - changeDist:sender
  93. {
  94.     int val = [sender intValue];
  95.     
  96.     [distText setIntValue:val];
  97.     if (sender != distSlider) [distSlider setIntValue:val];
  98.     return self;
  99. }
  100.  
  101. @end
  102.